/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package RunableClass.useClass;

import Alert.ST_name;
import java.awt.image.ImageObserver;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.Arrays;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import mysql.connect;

/**
 *
 * @author Anatomy
 */
public class Addport {
JTextField JF;
JTextField JF1;
    public Addport(JTextField JF,JTextField JF1) {
       this.JF=JF;
       this.JF1=JF1;
    }
    
    public void addport(){
        ST_name SN=new ST_name();
        if(!JF.getText().equals("")&&Arrays.binarySearch(ST_name.st, JF.getText())>0){
         connect a=   new connect();
                      String sqlsec="SELECT * FROM stock_port Where (SymbolName='"+JF.getText()+"')";
                       // System.out.println(sqlsec);
                      try {
                a.rs= a.stmt.executeQuery(sqlsec);
                a.rs.next();
                 //  System.out.println(a.rs.getRow() +"---->");
                if(a.rs.getRow()<=0){
                        String sql="INSERT INTO `stock_port` ("+
                               
                                "`SymbolName`,"+
                                "`amount`"+
                               " )"+
                                "VALUES ("+
                               "  '"+JF.getText().toUpperCase()+"'"+
                                 " ,'"+JF1.getText()+"'"+
                                ");";
            try {
                a.stmt.executeUpdate(sql);
            } catch (SQLException ex) {
            }
                        
                        a.CloseDB(); 
                    //    model.addRow(x);
                        { }javax.swing.JOptionPane.showMessageDialog(null,"Add "+JF.getText()+" and Amount "+JF1.getText()+"Complete! ","",JOptionPane.INFORMATION_MESSAGE);
                      JF.setText("");
                      JF1.setText("");
                }
            } catch (SQLException ex) {
            }
                  {        javax.swing.JOptionPane.showMessageDialog(null,"Add "+JF.getText()+" and Amount "+JF1.getText()+" Complete!","",JOptionPane.INFORMATION_MESSAGE);
                      JF.setText("");
                      JF1.setText("");
                     
    
        }}}
 
    
  public static Object Setcolor(String text){  
      Object color = null;
      if(text.startsWith("-")&&text.length()>2){
          color= "<html><font color='RED'>"+text+"</font></html>";
      }else if(text.startsWith("+")){
          color= "<html><font color='GREEN'>"+text+"</font></html>";
      }else{
            color= "<html><font color='BLACK'>"+text+"</font></html>";
      }
    
    
     return  color;
  }
  public static Object SetcolorZero(String text,String text1){  
       Object color = null;
      if(text.startsWith("-")&&text.length()>2){
          color= "<html><font color='RED'>"+Double.parseDouble(text)*Double.parseDouble(text1)+"</font></html>";
      }else if(text.startsWith("+")){
          color= "<html><font color='GREEN'>"+Double.parseDouble(text)*Double.parseDouble(text1)+"</font></html>";
      }else{
            color= "<html><font color='BLACK'>"+Double.parseDouble(text)*Double.parseDouble(text1)+"</font></html>";
      }
    
     return  color;
  }
    public static Object SetWithStatus(String text,String text1){  
      Object color = null;
      if(text1.startsWith("-")&&text1.length()>2){
          color= "<html><font color='RED'>"+text+"</font></html>";
      }else if(text1.startsWith("+")){
          color= "<html><font color='GREEN'>"+text+"</font></html>";
      }else{
            color= "<html><font color='BLACK'>"+text+"</font></html>";
      }
    
    
     return  color;
  }
   public static Object Setstatic(String text,int status){  
      Object color = null;
      if(status==0){
          color= "<html><font color='RED'>"+text+"</font></html>";
      }else if(status==1){
          color= "<html><font color='GREEN'>"+text+"</font></html>";
      }else{
            color= "<html><font color='BLACK'>"+text+"</font></html>";
      }
    
    
     return  color;
  }
  public static Object SetcolorArray(String text[]){  
      Object color = null;
      if(text[1].startsWith("-")&&text[1].length()>=2){
          
         color= "<html><font color='RED'>"+roundTwoDecimals(-(Double.parseDouble(text[1])+Double.parseDouble(text[0])))+"</font></html>";
      }else if(text[1].startsWith("+")){
          color= "<html><font color='GREEN'>"+roundTwoDecimals((Double.parseDouble(text[1])+Double.parseDouble(text[0])))+"</font></html>";
      }else{
            color= "<html><font color='BLACK'>-</font></html>";
      }
     
    
    
     return  color;
  }
  static double roundTwoDecimals(double d) {
        	DecimalFormat twoDForm = new DecimalFormat("#.##");
		return Double.valueOf(twoDForm.format(d));
}
}
